Print the floating point from mantissa, exponent pair¶
Print the floating point from mantissa, exponent pair.
Expected output:
Mantissa Exponent Floating point value
——– ——– ——————–
0.70 -3 0.09
0.30 0 0.30
0.50 3 4.00
import math
print('{:^7} {:^8} {:^17}'.format('Mantissa', 'Exponent', 'Floating point value'))
print('{:-^8} {:-^8} {:-^20}'.format('', '', ''))
for m, e in [ (0.7, -3),
(0.3, 0),
(0.5, 3),
]:
x = math.ldexp(m, e)
print('{:7.2f} {:7d} {:7.2f}'.format(m, e, x))
Output:
Mantissa Exponent Floating point value
-------- -------- --------------------
0.70 -3 0.09
0.30 0 0.30
0.50 3 4.00